# -*- coding: utf-8 -*-
# @Time : 2021/12/31 13:57
from flask import Flask
import redis
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from Common.yaml_method import YamlMethod


app = Flask(__name__)

# 读取配置信息
evn = YamlMethod().read_data('environment.yaml')['evn']
account = YamlMethod().read_data('account_info.yaml')['mysql'][evn]
case_path = YamlMethod().read_data('path.yaml')['import_case'][evn]
apk_file_path = YamlMethod().read_data('path.yaml')['apk_path'][evn]
photo_file_path = YamlMethod().read_data('path.yaml')['photo_path'][evn]

# 数据库配置
app.config['SECRET_KEY'] = account[3]  # 密码
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://%s:%s@%s:%s/%s' % (account[2], account[3], account[0],
                                                                            account[1], account[4])

# Redis配置
redis_host = 'localhost'
redis_port = 6379
redis_client = redis.StrictRedis(host=redis_host, port=redis_port, decode_responses=True)


app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['JSON_AS_ASCII'] = False
app.config["SQLALCHEMY_ECHO"] = False
# 配置数据库连接数
app.config['SQLALCHEMY_POOL_SIZE'] = 20
# 配置数据库连接数上线
app.config['SQLALCHEMY_MAX_OVERFLOW'] = 30
# 配置接收文件最大字节数
app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 10240
# 配置接收case文件类型
app.config['CASE_UPLOAD_EXTENSIONS'] = ['.xmind']
# 配置接收case文件保存路径
app.config['CASE_UPLOAD_PATH'] = case_path
# 配置接收apk文件类型
app.config['APK_UPLOAD_EXTENSIONS'] = ['.apk', '.ipa']
# 配置接收apk文件保存路径
app.config['APK_FILE_UPLOAD_PATH'] = apk_file_path
# 配置接收photo文件类型
app.config['PHOTO_UPLOAD_EXTENSIONS'] = ['.jpg', '.png', '.svg', '.jpeg', '.gif']
# 配置接收video文件类型
app.config['VIDEO_UPLOAD_EXTENSIONS'] = ['.mp4', '.MP4', '.3gp', '.m4v', '.MOV']
# 配置接收photo文件保存路径
app.config['PHOTO_FILE_UPLOAD_PATH'] = photo_file_path

db = SQLAlchemy(app)
ma = Marshmallow(app)
